package jaasConfig;

import java.security.Principal;
import java.util.Iterator;

import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

public class Tes {

	public static void main(String[] args) throws LoginException {

		LoginContext ctx = new LoginContext("SimpleLogin", new ConsoleCallbackHandler());
		ctx.login();
		Subject subj = ctx.getSubject();

		System.out.println("Login assigned these principals: ");
		Iterator it = subj.getPrincipals().iterator();
		while (it.hasNext()) {
			Principal pl = (Principal) it.next();
			System.out.println("\t" + pl.getName());
		}
		Subject.doAsPrivileged(subj, new MyAction(), null);

		ctx.logout();
	}

}
